Adding ICPC Live Archive
[andmenj-acm.git] / ICPC Live Archive / 3928 - Ballroom lights / help / gomox.ar-pap-2010-d9b17e5cb110 / tpb / doc / algorithmic.sty
blob4dcaa7c3601ed9c2d9ed83ab57b8ac2de7cf75c1
1 % ALGORITHMIC STYLE for LaTeX version 2e
3 % This style file is free software; you can redistribute it and/or
4 % modify it under the terms of the GNU Lesser General Public
5 % License as published by the Free Software Foundation; either
6 % version 2 of the License, or (at your option) any later version.
8 % This style file is distributed in the hope that it will be useful,
9 % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 % Lesser General Public License for more details.
13 % You should have received a copy of the GNU Lesser General Public
14 % License along with this style file; if not, write to the
15 % Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 % Boston, MA 02111-1307, USA.
18 \NeedsTeXFormat{LaTeX2e}
19 \ProvidesPackage{algorithmic}[2006/06/02]
20 \typeout{Document Style `algorithmic' - environment}
22 \RequirePackage{ifthen}
23 \RequirePackage{calc}
24 \RequirePackage{keyval}
25 \newboolean{ALC@noend}
26 \setboolean{ALC@noend}{false}
27 \newcounter{ALC@line}
28 \newcounter{ALC@rem}
29 \newcounter{ALC@depth}
30 \newlength{\ALC@tlm}
32 \DeclareOption{noend}{\setboolean{ALC@noend}{true}}
34 \ProcessOptions
36 % For keyval-style options
37 \def\algsetup{\setkeys{ALG}}
39 % For indentation of algorithms
40 \newlength{\algorithmicindent}
41 \setlength{\algorithmicindent}{0pt}
42 \define@key{ALG}{indent}{\setlength{\algorithmicindent}{#1}}
43 \ifthenelse{\lengthtest{\algorithmicindent=0pt}}%
44 {\setlength{\algorithmicindent}{1em}}{}
46 % For line numbers' delimiters
47 \newcommand{\ALC@linenodelimiter}{:}
48 \define@key{ALG}{linenodelimiter}{\renewcommand{\ALC@linenodelimiter}{#1}}
51 % For line numbers' size
52 \newcommand{\ALC@linenosize}{\footnotesize}
53 \define@key{ALG}{linenosize}{\renewcommand{\ALC@linenosize}{#1}}
56 % ALGORITHMIC
57 \newcommand{\algorithmicrequire}{\textbf{Require:}}
58 \newcommand{\algorithmicensure}{\textbf{Ensure:}}
59 \newcommand{\algorithmicparams}[1]{\textcolor{RawSienna}{\textbf{Entrada:}} #1}
60 \newcommand{\algorithmiccomment}[1]{\textcolor{Purple}{\{#1\}}}
61 \newcommand{\algorithmicend}{\textbf{end}}
62 \newcommand{\algorithmicif}{\textbf{if}}
63 \newcommand{\algorithmicthen}{\textbf{then}}
64 \newcommand{\algorithmicelse}{\textbf{else}}
65 \newcommand{\algorithmicelsif}{\algorithmicelse\ \algorithmicif}
66 \newcommand{\algorithmicendif}{\algorithmicend\ \algorithmicif}
67 \newcommand{\algorithmicfor}{\textbf{for}}
68 \newcommand{\algorithmicforall}{\textbf{for all}}
69 \newcommand{\algorithmicdo}{\textbf{do}}
70 \newcommand{\algorithmicendfor}{\algorithmicend\ \algorithmicfor}
71 \newcommand{\algorithmicwhile}{\textbf{while}}
72 \newcommand{\algorithmicendwhile}{\algorithmicend\ \algorithmicwhile}
73 \newcommand{\algorithmicloop}{\textbf{loop}}
74 \newcommand{\algorithmicendloop}{\algorithmicend\ \algorithmicloop}
75 \newcommand{\algorithmicrepeat}{\textbf{repeat}}
76 \newcommand{\algorithmicuntil}{\textbf{until}}
77 \newcommand{\algorithmicprint}{\textbf{print}}
78 \newcommand{\algorithmicreturn}{\textbf{return}}
79 \newcommand{\algorithmictrue}{\textbf{true}}
80 \newcommand{\algorithmicfalse}{\textbf{false}}
81 \def\ALC@setref{%
82 \def\@currentlabel{\theALC@line}%
84 \def\ALC@item[#1]{%
85 \if@noparitem \@donoparitem
86 \else \if@inlabel \indent \par \fi
87 \ifhmode \unskip\unskip \par \fi
88 \if@newlist \if@nobreak \@nbitem \else
89 \addpenalty\@beginparpenalty
90 \addvspace\@topsep \addvspace{-\parskip}\fi
91 \else \addpenalty\@itempenalty \addvspace\itemsep
92 \fi
93 \global\@inlabeltrue
94 \fi
95 \everypar{\global\@minipagefalse\global\@newlistfalse
96 \if@inlabel\global\@inlabelfalse \hskip -\parindent \box\@labels
97 \penalty\z@ \fi
98 \everypar{}}\global\@nobreakfalse
99 \if@noitemarg \@noitemargfalse \if@nmbrlist \refstepcounter{\@listctr}\fi \fi
100 \sbox\@tempboxa{\makelabel{#1}}%
101 \global\setbox\@labels
102 \hbox{\unhbox\@labels \hskip \itemindent
103 \hskip -\labelwidth \hskip -\ALC@tlm
104 \ifdim \wd\@tempboxa >\labelwidth
105 \box\@tempboxa
106 \else \hbox to\labelwidth {\unhbox\@tempboxa}\fi
107 \hskip \ALC@tlm}\ignorespaces}
109 \newenvironment{algorithmic}[1][0]{
110 \setcounter{ALC@depth}{\@listdepth}%
111 \let\@listdepth\c@ALC@depth%
112 \let\@item\ALC@item%
113 \newcommand{\ALC@lno}{%
114 \ifthenelse{\equal{\arabic{ALC@rem}}{0}}
115 {{\ALC@linenosize \arabic{ALC@line}\ALC@linenodelimiter}}{}%
117 \let\@listii\@listi
118 \let\@listiii\@listi
119 \let\@listiv\@listi
120 \let\@listv\@listi
121 \let\@listvi\@listi
122 \let\@listvii\@listi
123 \newenvironment{ALC@g}{
124 \begin{list}{\ALC@lno}{ \itemsep\z@ \itemindent\z@
125 \listparindent\z@ \rightmargin\z@
126 \topsep\z@ \partopsep\z@ \parskip\z@\parsep\z@
127 \leftmargin \algorithmicindent%1em
128 \addtolength{\ALC@tlm}{\leftmargin}
131 {\end{list}}
132 \newcommand{\ALC@it}{\refstepcounter{ALC@rem}\refstepcounter{ALC@line}\ifthenelse{\equal{\arabic{ALC@rem}}{#1}}{\setcounter{ALC@rem}{0}}{}\item\ALC@setref}
133 \newcommand{\ALC@com}[1]{\ifthenelse{\equal{##1}{default}}%
134 {}{\ \algorithmiccomment{##1}}}
135 \newcommand{\REQUIRE}{\item[\algorithmicrequire]}
136 \newcommand{\ENSURE}{\item[\algorithmicensure]}
137 \newcommand{\PRINT}{\ALC@it\algorithmicprint{}\ \ }
138 \newcommand{\RETURN}{\ALC@it\algorithmicreturn{}\ \ }
139 \newcommand{\TRUE}{\algorithmictrue{}}
140 \newcommand{\FALSE}{\algorithmicfalse{}}
141 \newcommand{\STATE}{\ALC@it}
142 \newcommand{\STMT}{\ALC@it}
143 \newcommand{\PARAMS}[1]{\item[\algorithmicparams{##1}]}
144 \newcommand{\COMMENT}[1]{\algorithmiccomment{##1}}
145 \newenvironment{ALC@if}{\begin{ALC@g}}{\end{ALC@g}}
146 \newenvironment{ALC@for}{\begin{ALC@g}}{\end{ALC@g}}
147 \newenvironment{ALC@whl}{\begin{ALC@g}}{\end{ALC@g}}
148 \newenvironment{ALC@loop}{\begin{ALC@g}}{\end{ALC@g}}
149 \newenvironment{ALC@rpt}{\begin{ALC@g}}{\end{ALC@g}}
150 \renewcommand{\\}{\@centercr}
151 \newcommand{\IF}[2][default]{\ALC@it\algorithmicif\ ##2\ \algorithmicthen%
152 \ALC@com{##1}\begin{ALC@if}}
153 \newcommand{\ELSE}[1][default]{\end{ALC@if}\ALC@it\algorithmicelse%
154 \ALC@com{##1}\begin{ALC@if}}
155 \newcommand{\ELSIF}[2][default]%
156 {\end{ALC@if}\ALC@it\algorithmicelsif\ ##2\ \algorithmicthen%
157 \ALC@com{##1}\begin{ALC@if}}
158 \newcommand{\FOR}[2][default]{\ALC@it\algorithmicfor\ ##2\ \algorithmicdo%
159 \ALC@com{##1}\begin{ALC@for}}
160 \newcommand{\FORALL}[2][default]{\ALC@it\algorithmicforall\ ##2\ %
161 \algorithmicdo%
162 \ALC@com{##1}\begin{ALC@for}}
163 \newcommand{\WHILE}[2][default]{\ALC@it\algorithmicwhile\ ##2\ %
164 \algorithmicdo%
165 \ALC@com{##1}\begin{ALC@whl}}
166 \newcommand{\LOOP}[1][default]{\ALC@it\algorithmicloop%
167 \ALC@com{##1}\begin{ALC@loop}}
168 \newcommand{\REPEAT}[1][default]{\ALC@it\algorithmicrepeat%
169 \ALC@com{##1}\begin{ALC@rpt}}
170 \newcommand{\UNTIL}[1]{\end{ALC@rpt}\ALC@it\algorithmicuntil\ ##1}
171 \ifthenelse{\boolean{ALC@noend}}{
172 \newcommand{\ENDIF}{\end{ALC@if}}
173 \newcommand{\ENDFOR}{\end{ALC@for}}
174 \newcommand{\ENDWHILE}{\end{ALC@whl}}
175 \newcommand{\ENDLOOP}{\end{ALC@loop}}
177 \newcommand{\ENDIF}{\end{ALC@if}\ALC@it\algorithmicendif}
178 \newcommand{\ENDFOR}{\end{ALC@for}\ALC@it\algorithmicendfor}
179 \newcommand{\ENDWHILE}{\end{ALC@whl}\ALC@it\algorithmicendwhile}
180 \newcommand{\ENDLOOP}{\end{ALC@loop}\ALC@it\algorithmicendloop}
182 \renewcommand{\@toodeep}{}
183 \begin{list}{\ALC@lno}{\setcounter{ALC@rem}{0}\setcounter{ALC@line}{0}%
184 \itemsep\z@ \itemindent\z@ \listparindent\z@%
185 \partopsep\z@ \parskip\z@ \parsep\z@%
186 \labelsep 0.5em \topsep 0.2em%
187 \ifthenelse{\equal{#1}{0}}
188 {\labelwidth 0.5em }
189 {\labelwidth 1.2em }
190 \leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep}
191 \ALC@tlm\labelsep
194 {\end{list}}